﻿using System;
using System.Runtime.Serialization;

namespace IntoNails.Models
{
    [Serializable]
    public class OrderDetails : ISerializable
    {
        #region Constructors

        protected OrderDetails()
        {
        }

        public OrderDetails(SerializationInfo info, StreamingContext context)
        {
            this.OrderCode = (Guid)info.GetValue("OrderCode", typeof(Guid));
            this.NailsServiceCode = (Guid)info.GetValue("NailsServiceCode", typeof(Guid));
            this.AssignTo = (Guid)info.GetValue("AssignTo", typeof(Guid));
            this.AppointmentTime = info.GetDateTime("AppointmentTime");
            this.IsCancelled = info.GetBoolean("IsCancelled");
        }

        #endregion

        #region Properties

        public Guid OrderCode { get; set; }
        public Guid NailsServiceCode { get; set; }

        public Guid AssignTo { get; set; }

        public DateTime AppointmentTime { get; set; }

        public bool IsCancelled { get; set; }

        #endregion

        public static OrderDetails CreateOrderDetails(Guid orderCode, Guid serviceCode, Guid assignedTo, DateTime appointmentTime)
        {
            return new OrderDetails
                       {
                           OrderCode = orderCode,
                           NailsServiceCode = serviceCode,
                           AssignTo = assignedTo,
                           AppointmentTime = appointmentTime,
                           IsCancelled = false
                       };
        }

        #region Implementation of ISerializable

        public void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            info.AddValue("OrderCode", this.OrderCode);
            info.AddValue("NailsServiceCode", this.NailsServiceCode);
            info.AddValue("AssignTo", this.AssignTo);
            info.AddValue("AppointmentTime", this.AppointmentTime);
            info.AddValue("IsCancelled", this.IsCancelled);
        }

        #endregion
    }
}
